package com.douqu.game.core.entity.world.map;


import com.bean.core.util.TimeUtils;
import com.douqu.game.core.config.map.CityArmyConfig;
import com.douqu.game.core.config.map.CityArmyGroupConfig;
import com.douqu.game.core.entity.battle.BattleTemp;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.protobuf.SGCommonProto;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-04-19 20:58
 */
public class SpriteGarrisonBean extends SpriteBean {

    /**
     * 军队ID
     */
    public int armyId;

    /**
     * 属性组ID
     */
    public int groupId;

    public SpriteGarrisonBean()
    {
        super();
    }

    public SpriteGarrisonBean(int tempId, int armyId, int groupId, int camp, int cityId, String masterPlayerIndex)
    {
        this();

        this.masterPlayerIndex = masterPlayerIndex;
        this.camp = camp;
        this.armyId = armyId;
        this.groupId = groupId;
        String uniqueId = "GA" + TimeUtils.getCurrentTime("ssSSS") + tempId;
        this.objectIndex = armyId + ConstantFactory.UNDERLINE + groupId + ConstantFactory.UNDERLINE + uniqueId + ConstantFactory.UNDERLINE + cityId;
        this.team = SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF;
        setCurCity(cityId);
        setStatus(SGCommonProto.E_ARMY_STATUS.ARMY_STATUS_MATCH);

        updateBaseInfo();
        initBattleTemp();
    }

//    @Override
//    public void loadFrom(ByteBuffer buffer)
//    {
//        super.loadFrom(buffer);
//
//        armyId = buffer.readInt();
//        groupId = buffer.readInt();
//    }
//
//    @Override
//    public void writeTo(ByteBuffer buffer)
//    {
//        super.writeTo(buffer);
//
//        buffer.writeInt(armyId);
//        buffer.writeInt(groupId);
//    }

    @Override
    public SGCommonProto.PlayerBaseInfo.Builder parseBaseInfo()
    {
        updateBaseInfo();

        return baseInfo.parseBaseInfo();
    }


    public void updateBaseInfo()
    {
        baseInfo.setObjectIndex(objectIndex);

        CityArmyConfig cityArmyConfig = DataFactory.getInstance().getGameObject(DataFactory.CITY_ARMY_KEY, armyId);
        baseInfo.setNickName(cityArmyConfig.name);
        baseInfo.setCamp(cityArmyConfig.camp);
        baseInfo.setAvatar(cityArmyConfig.master+"");

        CityArmyGroupConfig cityArmyGroupConfig = DataFactory.getInstance().getGameObject(DataFactory.CITY_ARMY_GROUP_KEY, groupId);
        baseInfo.setFc(cityArmyGroupConfig.fc);
        baseInfo.setLv(cityArmyGroupConfig.getLv());
    }

    public void initBattleTemp()
    {
        if(battleTemp == null)
        {
            battleTemp = new BattleTemp(this);
        }
    }

    @Override
    public String toString() {
        return "{" +
                "armyId=" + armyId +
                ", groupId=" + groupId +
                "}-" + super.toString();
    }
}
